package database

import (
	"gorm.io/gorm"
	. "hxy/repo/model"
)

// #region crud for gitmodel
func GetAllGitRepo() ([]GitModel, *gorm.DB) {
	var gitAll []GitModel
	re := Db.Find(&gitAll)
	return gitAll, re
}
func GitNameById(id int) (string, *gorm.DB) {
	var gitrepo GitModel
	re := Db.Where("ID = ?", id).Find(&gitrepo)
	return gitrepo.Name, re
}
func GitById(id int) (GitModel, *gorm.DB) {
	var gitrepo GitModel
	re := Db.Where("ID = ?", id).Find(&gitrepo)
	return gitrepo, re
}
func GitDeleteId(id int) (re *gorm.DB) {
	return Db.Delete(&GitModel{}, id)
}
func CreateGitRepo(_repo *GitModel) (err error) {

	//log.Print(_repo)
	re := Db.Create(_repo)
	print(_repo.ID)
	err = re.Error
	return
}
func ChangeGitRepoState(_repo GitModel) (re *gorm.DB) {
	return Db.Model(&_repo).Update("status", _repo.Status)
}

//#endregion

// #region crud for git auth
func AntuById(id uint) (GitAuth, *gorm.DB) {
	var auth GitAuth
	re := Db.Where("ID = ?", id).Find(&auth)
	return auth, re
}
func AuthGetAll() ([]GitAuth, *gorm.DB) {
	var gitAll []GitAuth
	re := Db.Find(&gitAll)
	return gitAll, re
}
func AnthDeleteId(id int) *gorm.DB {
	return Db.Delete(&GitAuth{}, id)
}
func AuthCreate(auth GitAuth) (err error) {
	re := Db.Create(&auth)
	err = re.Error
	return
}

//#endregion
